package com.gxa.controller.xxh.providermanagement;

import com.github.pagehelper.PageInfo;
import com.gxa.common.R;
import com.gxa.common.Status;
import com.gxa.entity.SysProviderProgress;
import com.gxa.service.ProviderFollowService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/*
*供应商跟进
 */
@Controller
@Api(value = "供应商跟进所有操作功能",tags = "供应商跟进管理API")
@RequiresRoles(value = {"超级管理员","院长"},logical = Logical.OR)
@RequestMapping(value = "/providerManagement/follow")
public class ProviderFollowController {

    @Autowired
    ProviderFollowService providerFollowService;
    /*
     * 分页查询供应商列表信息
     */
    @RequestMapping(value = "/findFollowList",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有供应商跟进信息接口",notes = "查询所有供应商跟进信息",httpMethod = "GET",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R findFollowList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize")Integer pageSize){

        return providerFollowService.findFollowList(currentPage, pageSize);
    }

    /*
     * 新增一条供应商跟进
     */
    @RequestMapping(value = "/addFollow",method = RequestMethod.POST)
    @ApiOperation(value = "新增跟进信息接口",notes = "新增一个供应商跟进",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R addFollow(@RequestBody @ApiParam(name = "sysProviderProgress",value = "供应商跟进实体") SysProviderProgress sysProviderProgress){
        R r = new R();

        if(sysProviderProgress != null){
            boolean b = providerFollowService.addFollow(sysProviderProgress);
            if (b == true){
                r.setCode(200);
                r.setMsg("添加成功");
            }
        }else {
            r.setCode(500);
            r.setMsg("添加失败");
            }
        return r;
    }

    /*
     *根据供应商名称查询跟进信息
     */
    @RequestMapping(value = "/findFollowListByName",method = RequestMethod.POST)
    @ApiOperation(value = "条件查询跟进信息接口",notes = "条件查询跟进信息",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "name",value = "供应商名称",paramType = "query",dataType = "String",required = true)
    })
    @ResponseBody
    public R findFollowListByName(@RequestParam(value="name") String name,@RequestParam(value="currentPage") Integer currentPage,@RequestParam(value="pageSize")Integer pageSize){
        R r = new R();
        if (name != null) {
            PageInfo<SysProviderProgress> followListByName = providerFollowService.findFollowListByName(name,currentPage,pageSize);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(followListByName);
        }else {
            r.fromStatus(Status.BAD_QUERY_PARAM);
        }
        return r;
    }

    /*
    *根据ID修改跟进信息
     */
    @RequestMapping(value = "/updateFollowById",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID修改跟进信息接口",tags = "根据ID修改跟进信息",httpMethod = "POST",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R updateFollowById(@RequestBody @ApiParam (name = "sysProviderProgress",value = "供应商跟进实体",required = true) SysProviderProgress sysProviderProgress){
        return providerFollowService.updateFollowById(sysProviderProgress);
    }

    /*
    * 根据ID删除跟进信息
    * */
    @RequestMapping(value = "/deleteFollowById")
    @ApiOperation(value = "根据ID删除跟进信息接口",tags = "根据ID删除跟进信息",httpMethod = "POST",response = R.class)
    @ApiImplicitParam(name = "id",value = "跟进id",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public R deleteFollowById(@RequestParam("id") Integer id){
        return providerFollowService.deleteFollowById(id);
    }
}
